package com.example.foodapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    //定义控件
    Button btnRegister,btnCancel;
    EditText etRegisterPhone,etRegisterPassword,etRegisterPassword2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
    }

    //取消注册，点击后返回登陆界面
    public void registerCancel(View view) {
        Intent intent=new Intent(RegisterActivity.this,MainActivity.class);
        startActivity(intent);

        initView();
        setOnclick();
    }

    //设置监听器
    private void setOnclick() {
        btnRegister.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
    }

    //初始化控件
    private void initView() {
        btnRegister=findViewById(R.id.btn_register);
        btnCancel=findViewById(R.id.btn_cancel);
        etRegisterPhone=findViewById(R.id.et_register_phone);
        etRegisterPassword=findViewById(R.id.et_register_password);
        etRegisterPassword2=findViewById(R.id.et_register_password2);
    }

    //监听实例
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_register:
                register();
                break;
            case R.id.btn_cancel:
                finish();
                break;
        }
    }

    //注册
    private void register() {
        Map<String, String> map = new HashMap<>();

        String phone=etRegisterPhone.getText().toString();
        String password=etRegisterPassword.getText().toString();
        String password2=etRegisterPassword2.getText().toString();
        if (password.equals(password2)){
            map.put("phone",phone);
            map.put("password",password);
        }else {
            Toast.makeText(RegisterActivity.this,"两次密码输入不一致，请重新输入",Toast.LENGTH_SHORT).show();
            return;
        }
        if (phone.equals("")||password.equals("")||password2.equals("")){
            Toast.makeText(RegisterActivity.this,"输入不可为空，请重新输入",Toast.LENGTH_SHORT).show();
            return;
        }




    }
}